home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #2 / Amiga Plus CD - 1995 - No. 2.iso / internet / faq / englisch / z-shell < prev    next >
Encoding:
Text File  |  1995-04-11  |  39.4 KB  |  855 lines

  1. Archive-Name: unix-faq/shell/zsh
  2. Last-Modified: 1995/2/24
  3. Submitted-By: pws@amtp.liv.ac.uk (Peter Stephenson)
  4. Version: $Id: zsh.FAQ,v 1.34 1995/02/24 16:16:09 pws Exp pws $
  5. Frequency: Monthly
  6.  
  7. This document contains a list of frequently-asked (or otherwise
  8. significant) questions concerning the Z-shell, a command interpreter for
  9. many UNIX systems which is freely available to anyone with FTP access.
  10. Zsh is more powerful than every other common shell (sh, ksh, csh, tcsh
  11. and bash) put together.
  12.  
  13. Information on zsh is now available via the World Wide Web.  The
  14. address is in transition, but you can currently use
  15. "http://mal9000.bevc.blacksburg.va.us/zsh/zsh_home.shtml".  The server
  16. provides this FAQ and much else (thanks to Mark Borges for this).
  17.  
  18. If you have never heard of `sh', `csh' or `ksh', then you are probably
  19. better off to start by reading a general introduction to UNIX rather
  20. than this document.
  21.  
  22. Another useful source of information is the collection of FAQ articles
  23. posted frequently to the Usenet news groups comp.unix.questions,
  24. comp.unix.shells and comp.answers with answers to general questions
  25. about UNIX.  The fifth of the seven articles deals with shells,
  26. including zsh, with a brief description of differences.  (This article
  27. also talks about shell startup files which would otherwise rate a
  28. mention here.)
  29.  
  30. If you just want to know how to get your hands on the latest version,
  31. skip to question 4); if you want to know what to do with insoluble
  32. problems, go to 22).
  33.  
  34. To encourage you to read on, if you don't know about zsh but are
  35. familiar with other UNIX shells, here are some things that zsh is
  36. particularly good at.  No claim of exclusivity is made, especially as
  37. shells copy one another, though in the areas of command line editing and
  38. globbing zsh is well ahead of the competition.  I am not aware of a
  39. major feature in any other freely-available shell which zsh does not
  40. also have.
  41.   Command line editing:
  42.     programmable completion: incorporates the ability to use
  43.       the full power of zsh globbing (compctl -g),
  44.     multi-line commands editable as a single buffer (even files!),
  45.     variable editing (vared),
  46.     command buffer stack,
  47.     print text straight into the buffer for immediate editing (print -z),
  48.     execution of unbound commands,
  49.     menu completion,
  50.     variable, editing function and option name completion,
  51.     inline expansion of variables, history commands.
  52.   Globbing --- extremely powerful, including:
  53.     recursive globbing (cf. find),
  54.     file attribute qualifiers (size, type, etc. also cf. find),
  55.     full alternation and negation of patterns.
  56.   Handling of multiple redirections (simpler than tee).
  57.   Large number of options for tailoring.
  58.   Path expansion (=foo -> /usr/bin/foo).
  59.   Adaptable messages for spelling, watch, time as well as prompt
  60.     (now including conditional expressions).
  61.   Named directories.
  62.   Comprehensive integer arithmetic.
  63.   Manipulation of arrays (including reverse subscripting).
  64.   Spelling correction.
  65.  
  66. Notation: Quotes `like this' are ordinary textual quotation
  67. marks.  Other uses of quotation marks are input to the shell.
  68.  
  69. If you are reading this file with GNU Emacs 19 and have my
  70. cross-referencing package xref.el (available from
  71. suna.amtp.liv.ac.uk:/pub/pws), I can supply a suitable set of
  72. cross-references to make reading the file easier.
  73.  
  74. Contents:
  75. 1) What is it?
  76. 2) On what machines will it run?  (Plus important compilation notes)
  77. 3) What's the latest version?
  78. 4) Where do I get it?
  79. 5) How does zsh differ from sh, ksh, csh, tcsh, bash?
  80. 6) Why do my csh aliases not work?  (Plus other alias pitfalls.)
  81. 7) How do I turn off spelling correction for an individual command?
  82. 8) How do I get the meta key to work on my xterm?
  83. 9) Why does my terminal act funny in way x?
  84. 10) Why does `$var' where var="foo bar" not do what I expect?
  85. 11) Why do my autoloaded functions not autoload [the first time]?
  86. 12) How does base arithmetic work?
  87. 13) How do I get a newline in my prompt?
  88. 14) Why does `bindkey ^a command-name' or 'stty intr ^-' do something funny?
  89. 15) Why can't I bind \C-s and \C-q any more?
  90. 16) How do I execute command `foo' within function `foo'?
  91. 17) Why do history substitutions with single bangs do something funny?
  92. 18) Why does zsh kill off all my background jobs when I logout?
  93. 19) I don't have root access: how do I make zsh my login shell?
  94. 20) Shouldn't zsh be more/less like ksh/(t)csh?
  95. 21) What bugs are currently known and unfixed?
  96. 22) Where do I report bugs, get more info / who's working on zsh?
  97. 23) What's on the wish-list?
  98. --- End of Contents ---
  99.  
  100.  
  101. 1) What is it?
  102.  
  103.   Zsh is a UNIX command interpreter (shell) which of the standard shells
  104.   most resembles the Korn shell (ksh), although it is not completely
  105.   compatible.  It includes enhancements of many types, notably in the
  106.   command-line editor, options for customising its behaviour, filename
  107.   globbing, features to make C-shell (csh) users feel more at home and
  108.   extra features drawn from tcsh (another `custom' shell).
  109.  
  110.   It was written by Paul Falstad when a student at Princeton; however,
  111.   Paul doesn't maintain it any more and enquiries should be sent to
  112.   the mailing list (see question 22).  It is freely available to
  113.   anyone under unrestrictive conditions.
  114.  
  115.   For more information, the files doc/intro.txt or doc/intro.troff
  116.   included with the source distribution are highly recommended.  A list
  117.   of features is given in FEATURES, also with the source.
  118.  
  119.  
  120. 2) On what machines will it run?
  121.  
  122.   Zsh was written for machines of the Berkeley UNIX family; most such
  123.   machines (and all the most popular) will run it without major
  124.   surgery.  Modifications have been made so that it works under
  125.   SYSVR4-based operating systems such as Solaris 2.x and OSF/1.  The
  126.   best thing is to suck it and see.  Success has been obtained on
  127.   older SYSVR3 systems, but you may need to modify the code.
  128.   
  129.   The installation mechanism has recently been altered to use GNU
  130.   Autoconf, which should make it easier to recognise new machine
  131.   types.  If you need to change something to support a new machine, it
  132.   would be appreciated if you could add any necesssary preprocessor
  133.   code and alter configure.in to configure zsh automatically, then
  134.   send the required context diffs to the list (see question 22).
  135.  
  136.   *Note for Solaris 2.2 and 2.3*: The UCB versions of the routines for
  137.   reading directories are broken.  Make sure you compile without any
  138.   reference to /usr/ucblib in (e.g.) your LD_LIBRARY_PATH.  The
  139.   symptom of this is that globbed filenames will be missing the first
  140.   two letters.
  141.  
  142.   *Note for OSF/1 3.0*: There is apparently a bug in the header file
  143.   /usr/include/rpcsvc/ypclnt.h; the prototype for yp_all() has a
  144.   struct ypall_callback as its final argument, which should be a
  145.   pointer (struct ypall_callback *).  This prevents compilation of
  146.   zle_tricky.c.  If you can't modify the header file, copy it to the
  147.   current directory, modify that copy, and put a `-I.' argument into
  148.   CFLAGS in Makefile for the Src subdirectory when compiling.
  149.  
  150.  
  151. 3) What's the latest version?
  152.   
  153.   Zsh 2.5.0 has recently been released; the final form is 2.5.03.
  154.   Many bugs have been fixed since 2.3.1, which was the last major
  155.   release, and there are many new features, notably programmable
  156.   completion.  This version is known to have a bug with pipelines
  157.   inside other shell structures (now fixed in 2.6).
  158.  
  159.   Work has now started on 2.6 and 2.6-beta4 is available; note that
  160.   even numbered minor versions are not released.  Development of zsh
  161.   is usually patch by patch, with each intermediate version publicly
  162.   available.  Note that this `open' development system does mean bugs
  163.   are sometimes introduced into the most recent archived version.
  164.   These are usually fixed quickly.  Note also that as the shell
  165.   changes, it may become incompatible with older versions; see the end
  166.   of question 21 for a partial list.
  167.  
  168.  
  169. 4) Where do I get it?
  170.  
  171.   Richard Coleman (zsh@math.gatech.edu) is in charge of the archive.
  172.   There are various mirrors:
  173.       ftp.math.gatech.edu:/pub/zsh
  174.     ftp.sterling.com:/zsh
  175.     ftp.cenatls.cena.dgac.fr:/pub/shells/zsh
  176.     mrrl.lut.ac.uk:/zsh
  177.   The latest full release is in zsh-2.5.03.tar.gz in these
  178.   directories.  Note that this is in gzip format: you will need GNU
  179.   gzip from your nearest GNU archive to unpack it.  The
  180.   up-to-the-minute development version is in zsh-2.6-beta3.tar.gz.
  181.   There is also a version under RCS control which may be more suitable
  182.   for source hackers.
  183.  
  184.  
  185. 5) How does zsh differ from sh, ksh, csh, tcsh, bash?
  186.  
  187.   As has already been mentioned, zsh is most similar to ksh, while many
  188.   of the additions are to please csh users.
  189.  
  190.   i) ksh:
  191.  
  192.   Most features of ksh (and hence also of sh) are implemented in zsh;
  193.   problems can arise because the implementation is slightly different.
  194.   Note also that not all ksh's are the same either.  I have based this
  195.   on the 11/16/88f version of ksh.
  196.  
  197.   Various options can be turned on which will increase ksh
  198.   compatibility, though decrease zsh's abilities: see the manual
  199.   entries for GLOB_SUBST, IGNORE_BRACES (though brace expansion occurs
  200.   in some versions of ksh), KSH_OPTION_PRINT, NO_BANG_HIST, NO_EQUALS,
  201.   NO_HUP, NO_NOMATCH, NO_RCS, NO_SHORT_LOOPS, PROMPT_SUBST,
  202.   RM_STAR_SILENT, SH_WORD_SPLIT (see question 10) and SINGLE_LINE_ZLE.
  203.   Of these, SH_WORD_SPLIT and NO_NOMATCH are the most likely to spoil
  204.   your ksh scripts if unset.  Note that you can also disable any
  205.   built-in commands which get in your way.  If invoked as `ksh', the
  206.   shell will try and set suitable options.
  207.  
  208.   Here are some differences from ksh which might prove significant for
  209.   ksh programmers, some of which may be interpreted as bugs; there must
  210.   be more.  Note that this list is deliberately rather full and that
  211.   most of the items are fairly minor.  Those marked `*' perform in a
  212.   ksh-like manner if the shell is invoked with the name `ksh'.
  213.   Capitalised words with underlines refer to shell options.
  214.   
  215.   Syntax:
  216.   * Shell word splitting: see question 10).  (This is particularly
  217.       frequently asked about; use SH_WORD_SPLIT.)
  218.     Arrays are more csh-like than ksh-like:
  219.       subscripts start at 1, not 0; array[0] refers to array[1];
  220.       `$array' refers to the whole array, not $array[0];
  221.       braces are unnecessary: $a[1] == ${a[1]}, etc.
  222.     Coprocesses are established by `coproc'; `|&' behaves like csh.
  223.     Opening for both input and output via <> is not yet supported.
  224.   Command line substitutions, globbing etc.:
  225.   * Failure to match a globbing pattern causes an error (use
  226.       NO_NOMATCH).
  227.   * The results of parameter substitutions are treated as plain text:
  228.       `foo="*"; print $foo' prints all files in ksh but * in zsh.
  229.       (GLOB_SUBST has just been added to fix this.)
  230.     The $((...)) version of numeric evaluation was not available before
  231.       version 2.6 (use $[...]).
  232.     Treatment of backslashes within backquotes is subtly different.
  233.     $PSn do not do parameter substitution by default (use PROMPT_SUBST).
  234.     Globbing does not allow ksh-style `pattern-lists'.  Equivalents:
  235.       -------------------------------------------------------------------
  236.              ksh             zsh          Meaning
  237.             -----           -----        ---------
  238.            !(foo)            ^foo        Anything but foo.
  239.                       or   foo1~foo2     Anything matching foo1 but foo2.
  240.       @(foo1|foo2|...)  (foo1|foo2|...)  One of foo1 or foo2 or ...
  241.            ?(foo)           (foo|)       Zero or one occurrences of foo.
  242.            *(foo)           (foo)#       Zero or more occurrences of foo.
  243.            +(foo)           (foo)##      One or more occurrences of foo.
  244.       -------------------------------------------------------------------
  245.       The last two (with `#') require EXTENDED_GLOB.
  246.     Unquoted assignments do file expansion after ':'s (intended for PATHs).
  247.     `integer' does not allow -i; integers in bases other than 10 do not
  248.       have "base#" prefixed to them when printed.
  249.   Command execution:
  250.   * There is no $ENV variable (use /etc/zshrc, ~/.zshrc; note also $ZDOTDIR).
  251.     $PATH is not searched for commands specified at invocation without -c.
  252.   Aliases and functions:
  253.     The order in which aliases and functions are defined is significant
  254.       (function definitions with () expand aliases -- see question 6).
  255.     Aliases and functions cannot be exported.
  256.     There are no tracked aliases: command hashing replaces these.
  257.     The use of aliases for key bindings is replaced by `bindkey'.
  258.   Traps and signals:
  259.     By default, background jobs are killed when you log out:  see 18).
  260.     Traps and options are not local to functions; traps are not reset
  261.       automatically when called; traps are called as functions themselves
  262.       (this is a bug for the `trap "..." NAL' form of trap setting).
  263.     TRAPERR has become TRAPZERR (this was forced by UNICOS which has SIGERR).
  264.   Editing:
  265.     The options emacs, gmacs, trackall, viraw are not supported.
  266.       Use bindkey to change the editing behaviour: `set -o {emacs,vi}' 
  267.       become `bindkey -{e,v}'; for gmacs, go to emacs mode and use
  268.       `bindkey \^t gosmacs-transpose-characters'.  `Trackall' is replaced
  269.       by `hashcmds'.
  270.     The `keyword' option does not exist and -k is instead interactivecomments.
  271.       (`keyword' will not be in the next ksh release either.)
  272.     Management of histories in multiple shells is different:
  273.       the history list is not saved and restored after each command.
  274.     \ does not escape editing chars (use ^V).
  275.     Not all ksh bindings are set (e.g. `<ESC>#'; try <ESC>q).
  276.   * # in an interactive shell is not treated as a comment by default.
  277.   Built-in commands:
  278.     Some built-ins (r, autoload, history, integer ...) were aliases in ksh.
  279.     There is no built-in command newgrp: use e.g. `alias newgrp="exec newgrp"'
  280.     `jobs' has no `-n' flag.
  281.     `read' has no `-s' flag.
  282.     In `let "i = foo"', foo is evaluated as a number, not an expression
  283.       (although in `let "i = $foo"' it is treated as an expression).
  284.       The behaviour of ((...)) has just changed so that a `$foo' here is
  285.       also treated as a single number.
  286.   Other idiosyncrasies:
  287.     `select' always redisplays the list of selections on each loop.
  288.  
  289.   ii) csh:
  290.  
  291.   Although certain features aim to ease the withdrawal symptoms of csh
  292.   (ab)users, the syntax is in general rather different and you should
  293.   certainly not try to run scripts without modification.  The c2z script
  294.   is provided with the source (in scripts/c2z) to help convert .cshrc
  295.   and .login files; see also the next question concerning aliases,
  296.   particularly those with arguments.
  297.  
  298.   Csh-compatibility additions include:
  299.     Logout, rehash, source, (un)limit built-in commands.
  300.     *rc file for interactive shells.
  301.     Directory stacks.
  302.     Cshjunkie*, ignoreeof options.
  303.     The CSH_NULL_GLOB option.
  304.     >&, |& etc. redirection.
  305.     foreach ... loops; alternative syntax for other loops.
  306.     Alternative syntax `if ( ... ) ...' (also `for', `which'; this now
  307.       requires the CSH_JUNKIE_PAREN option).
  308.     $PROMPT as well as $PS1, $status as well as $?, $#argv as well as $#, ....
  309.     Escape sequences via % for prompts.
  310.     Special array variables $PATH etc. are colon-separated, $path are arrays.
  311.     !-type history (which may be turned off via `setopt nobanghist').
  312.     Arrays have csh-like features (see i)).
  313.  
  314.   iii) tcsh:
  315.  
  316.   (The previous section applies too, of course.)  Certain features have
  317.   been borrowed from tcsh, including $watch, run-help, $savehist,
  318.   $histlit, periodic commands etc., extended prompts, sched and
  319.   which/where built-ins.  Programmable completion was inspired by, but
  320.   is entirely different to, tcsh's `complete'. (There is a perl script
  321.   called lete2ctl in the scripts directory of the source distribution to
  322.   convert `complete' to `compctl' statements.)  This list is not
  323.   definitive: some features have gone in the other direction.
  324.  
  325.   If you're missing the editor function run-fg-editor, try something
  326.   with bindkey -s (which binds a string to a keystroke), e.g.
  327.     bindkey -s '^z' '\eqfg %$EDITOR:t\n'
  328.   which pushes the current line onto the stack and tries to bring a job
  329.   with the basename of your editor into the foreground.  Bindkey -s
  330.   allows limitless possibilities along these lines.
  331.  
  332.   iv) bash:
  333.   
  334.   Zsh has almost all the features that bash has (and much more); in
  335.   addition it is about twice as fast, though this is less impressive
  336.   than it sounds.  With the new malloc by Sven Wischnowsky (only used if
  337.   you arranged for USE_ZSH_MALLOC to be defined in config.h when
  338.   compiling zsh), zsh uses about the same amount of heap memory as bash,
  339.   which was previously the biggest gripe.  The only feature I am aware
  340.   of that zsh doesn't have is setting a numerical value for ignoreeof
  341.   --- it's always 10 --- but of course I don't use bash :-).
  342.  
  343.   However, zsh has no claims towards Posix compliancy and will not use
  344.   GNU readline (zle is more powerful).  In fact, bash is intended more
  345.   as an enhanced sh than a ksh work-alike; it doesn't handle [[ ... ]],
  346.   for example.
  347.  
  348.  
  349. 6) Why do my csh aliases not work?  (Plus other alias pitfalls.)
  350.  
  351.   First of all, check you are using the syntax
  352.     alias newcmd='list of commands'
  353.   and not
  354.     alias newcmd 'list of commands'
  355.   which won't work. (It tells you if `newcmd' and `list of commands' are
  356.   already defined as aliases.)
  357.  
  358.   Otherwise, your aliases probably contain references to the command
  359.   line of the form `\!*', etc.  Zsh does not handle this behaviour as it
  360.   has shell functions which provide a way of solving this problem more
  361.   consistent with other forms of argument handling.  For example, the
  362.   csh alias
  363.     alias cd 'cd \!*; echo $cwd'
  364.   can be replaced by the zsh function,
  365.     cd() { builtin cd $*; echo $PWD; }
  366.   (the `builtin' tells zsh to use its own `cd', avoiding an infinite loop)
  367.   or, perhaps better,
  368.     cd() { builtin cd $*; print -D $PWD; }
  369.   (which converts your home directory to a ~).  In fact, this problem is
  370.   better solved by defining the special function chpwd() (see the manual).
  371.   Note also that the `;' at the end of the function is optional in zsh,
  372.   but not in ksh or sh (for sh's where it exists).
  373.  
  374.   Here is Bart Schaefer's guide to converting csh aliases for zsh.
  375.  
  376.     1.  If the csh alias references "parameters" (\!:1 \!* etc.),
  377.         then in zsh you need a function (referencing $1 $* etc.).
  378.         Otherwise, you can use a zsh alias.
  379.  
  380.     2.  If you use a zsh function, you need to refer _at_least_ to
  381.         $* in the body (inside the { }).  Parameters don't magically
  382.         appear inside the { } the way they get appended to an alias.
  383.     
  384.     3.  If the csh alias references its own name (alias rm "rm -i"),
  385.         then in a zsh function you need the "command" keyword
  386.         (function rm() { command rm -i $* }), but in a zsh alias
  387.         you don't (alias rm="rm -i").
  388.  
  389.     4.  If you have aliases that refer to each other (alias ls "ls -C";
  390.         alias lf "ls -F" ==> lf == ls -C -F) then you must either:
  391.         a.  convert all of them to zsh functions; or
  392.         b.  after converting, be sure your .zshrc defines all of your
  393.             aliases before it defines any of your functions.
  394.  
  395.     Those first four are all you really need, but here are four more for
  396.     heavy csh alias junkies:
  397.  
  398.     5.  Mapping from csh alias "parameter referencing" into zsh function
  399.         (assuming shwordsplit is NOT set in zsh):
  400.              csh                   zsh
  401.             =====               ==========
  402.             \!*                 $*              (or $argv)
  403.             \!^                 $1              (or $argv[1])
  404.             \!:1                $1
  405.             \!:2                $2              (or $argv[2], etc.)
  406.             \!$                 $*[$#]          (or $argv[$#], or $*[-1])
  407.             \!:1-4              $*[1,4]
  408.             \!:1-               $*[1,$#-1]      (or $*[1,-2])
  409.             \!^-                $*[1,$#-1]
  410.             \!*:q               "$@"            ($*:q doesn't work (yet))
  411.             \!*:x               $=*             ($*:x doesn't work (yet))
  412.  
  413.     6.  Remember that it is NOT a syntax error in a zsh function to
  414.         refer to a position ($1, $2, etc.) greater than the number of
  415.         parameters. (E.g., in a csh alias, a reference to \!:5 will
  416.         cause an error if 4 or fewer arguments are given; in a zsh
  417.     function, $5 is the empty string if there are 4 or fewer
  418.     parameters.)
  419.  
  420.     7.  To begin a zsh alias with a - (dash, hyphen) character, use
  421.         "alias --":
  422.                  csh                            zsh
  423.             ===============             ==================
  424.             alias - "fg %-"             alias -- -="fg %-"
  425.  
  426.     8.  Stay away from "alias -g" in zsh until you REALLY know what
  427.         you're doing.
  428.  
  429.   There is one other serious problem with aliases: consider
  430.         alias l='/bin/ls -F'
  431.         l() { /bin/ls -la $* | more }
  432.   `l' in the function definition is in command position and is expanded
  433.   as an alias, defining `/bin/ls' and `-F' as functions which call
  434.   `/bin/ls', which gets a bit recursive.  This can be avoided if you use
  435.   `function' to define a function, which doesn't expand aliases.  It is
  436.   possible to argue for extra warnings somewhere in this mess.  Luckily,
  437.   it is not possible to define `function' as an alias.
  438.  
  439.  
  440. 7) How do I turn off spelling correction for an individual command?
  441.  
  442.   You presumably have `setopt correctall' in an initialisation file, so
  443.   that zsh checks the spelling of each word in the command line.  You
  444.   probably do not want this behaviour for commands which do not operate
  445.   on existing files.
  446.   
  447.   The answer is to alias the offending command to itself with
  448.   `nocorrect' stuck on the front, e.g.
  449.        alias mkdir='nocorrect mkdir'
  450.  
  451.  
  452. 8) How do I get the meta key to work on my xterm?
  453.  
  454.   As stated in the manual, zsh needs to be told about the meta key by
  455.   using `bindkey -me' or `bindkey -mv' in your .zshrc or on the command
  456.   line.  You probably also need to tell the terminal driver to allow the
  457.   `meta' bit of the character through; `stty pass8' is the usual
  458.   incantation.  Sample .zshrc entry:
  459.     [[ $TERM = "xterm" ]] && stty pass8 && bindkey -me
  460.   or, on SYSVR4-ish systems without pass8,
  461.     [[ $TERM = "xterm" ]] && stty -parenb -istrip cs8 && bindkey -me
  462.   (disable parity detection, don't strip high bit, use 8-bit characters).
  463.   Make sure this comes *before* any bindkey entries in your .zshrc which
  464.   redefine keys normally defined in the emacs/vi keymap.
  465.  
  466.  
  467. 9) Why does my terminal act funny in way x?
  468.  
  469.   If you are using an OpenWindows cmdtool as your terminal, any
  470.   escape sequences (such as those produced by cursor keys) will be
  471.   swallowed up and never reach zsh.  Either use shelltool or avoid
  472.   commands with escape sequences.  You can also disable scrolling from
  473.   the cmdtool pane menu (which effectively turns it into a shelltool).
  474.   If you still want scrolling, try using an xterm with the scrollbar
  475.   activated.
  476.  
  477.   If that's not the problem, and you are using stty to change some tty
  478.   settings, make sure you haven't asked zsh to freeze the tty settings:
  479.   type
  480.     ttyctl -u
  481.   before any stty commands you use.
  482.  
  483.   On the other hand, if you aren't using stty and have problems you may
  484.   need the opposite:  `ttyctl -f' freezes the terminal to protect it
  485.   from hiccups introduced by other programmes (kermit has been known to
  486.   do this).
  487.  
  488.   If _that's_ not the problem, and you are having difficulties with
  489.   external commands (not part of zsh), and you think some terminal
  490.   setting is wrong (e.g. ^V is getting interpreted as `literal next
  491.   character' when you don't want it to be), try
  492.     ttyctl -u
  493.     STTY='lnext "^-"' commandname
  494.   (in this example), or just export STTY for all commands to see.  Note
  495.   that zsh doesn't reset the terminal completely afterwards: just the
  496.   modes it uses itself and a number of special processing characters
  497.   (see the stty(1) manual page).
  498.  
  499.   After the release of version 2.5, there is likely to be an overhaul
  500.   which allows the terminal modes used by the shell to be modified
  501.   separately from those seen by external programmes.  This is partially
  502.   implemented already:  in 2.5, the shell will be less susceptible to
  503.   mode changes inherited from programmes.
  504.  
  505.  
  506. 10) Why does `$var' where var="foo bar" not do what I expect?
  507.  
  508.   In most Bourne-shell derivatives, multi-word variables such as
  509.     var="foo bar"
  510.   are split into words when passed to a command or used in a `for foo in
  511.   $var' loop.  By default, zsh does not have that behaviour: the
  512.   variable remains intact.  (This is not a bug!  See below.)  An option
  513.   (shwordsplit) exists to provide compatibility.
  514.   
  515.   For example, defining the function args to show the number of its
  516.   arguments:
  517.     args() { echo $#; }
  518.   and with our definition of vble,
  519.     args $vble
  520.   produces the output `1'.  After
  521.     setopt shwordsplit
  522.   the same function produces the output `2', as with sh and ksh.
  523.   
  524.   Unless you need strict sh/ksh compatibility, you should ask yourself
  525.   whether you really want this behaviour, as it can produce unexpected
  526.   effects for variables with entirely innocuous embedded spaces.  The
  527.   natural way to produce word-splitting behaviour in zsh is via arrays.
  528.   For example,
  529.     set -A array one two three twenty
  530.   (or
  531.         array=(one two three twenty)
  532.   if you prefer), followed by
  533.     args $array
  534.   produces the output `4', regardless of the setting of shwordsplit.
  535.   Arrays are also much more versatile than single strings.
  536.  
  537.   Note also the "$@" method of word splitting is always available in zsh
  538.   functions and scripts (though strictly this does array splitting, not
  539.   word splitting), also the substitution ${=foo} to turn on word
  540.   splitting on variable `foo'.
  541.  
  542.   Shwordsplit is set when zsh is invoked with the name `ksh'.
  543.  
  544.  
  545. 11) Why do my autoloaded functions not autoload [the first time]?
  546.  
  547.   When you put a shell function in an autoload directory (i.e. one
  548.   mentioned in $FPATH), it should be written just as if it were a
  549.   shell script.  In other words, there should be no line at the
  550.   beginning saying `function foo {' or `foo () {', and consequently no
  551.   matching '}' at the end.  If you include those, then the first time
  552.   you try to use the function, the _whole_ file is run --- in other
  553.   words, zsh simply defines the function and does nothing else.
  554.  
  555.   As a concrete example, if you have a function which you would define
  556.   on the command line as `xhead () { print -n "\033]2;$*\a"; }' and
  557.   your have assigned `FPATH=~/fns', then your .zshrc should contain
  558.   `autoload xhead' and the file ~/fns/xhead should contain only
  559.   `print -n "\033]2;$*\a"'.  (A neat trick to autoload all functions
  560.   in a given directory is to include a line like `autoload ~/fns/*(:t)'
  561.   in .zshrc; the bit in parentheses removes the directory part of the
  562.   filenames, leaving just the function names.)
  563.  
  564.   The shell may soon be enhanced to allow the Korn shell syntax, where
  565.   the file contains the whole function including the definition lines.
  566.   However, the form given above is unlikely to disappear as it allows
  567.   significant benefits, including using a function directly as a script,
  568.   and being able to link a function under different names.
  569.  
  570.  
  571. 12) How does base arithmetic work?
  572.  
  573.   The ksh syntax is now understood, i.e.
  574.         let 'foo = 16#ff'
  575.   or equivalently
  576.         (( foo = 16#ff ))
  577.   or even
  578.         foo=$[16#ff]
  579.   (note that `foo=$((16#ff))' is supported from version 2.6 onward).
  580.   The original syntax was
  581.     (( foo = [16]ff ))
  582.   --- this was based on a misunderstanding of the ksh manual page.  It
  583.   still works but its use is deprecated.
  584.   Then
  585.     echo $foo
  586.   gives the answer `255'.  It is possible to declare variables explicitly
  587.   to be integers, via
  588.     typeset -i foo
  589.   which has a different effect: namely the base used in the first
  590.   assignment (hexadecimal in the example) is subsequently used whenever
  591.   `foo' is displayed (although the internal representation is unchanged).
  592.   To ensure foo is always displayed in decimal, declare it as
  593.     typeset -i 10 foo
  594.   which requests base 10 for output.  You can change the output base of an
  595.   existing variable in this fashion.  Using the `$[ ... ]' method will
  596.   always display in decimal.
  597.  
  598.  
  599. 13) How do I get a newline in my prompt?
  600.  
  601.   You can place a literal newline in quotes, i.e.
  602.     PROMPT="Hi Joe,
  603.     what now?%# "
  604.   If you have the bad taste to set the option cshjunkiequotes, which
  605.   inhibits such behaviour, you will have to bracket this with 
  606.   `unsetopt cshjunkiequotes' and `setopt cshjunkiequotes', or put it in
  607.   your .zshrc before the option is set.
  608.   
  609.   Arguably the prompt code should handle `print'-like escapes.  Feel
  610.   free to write this :-).
  611.  
  612.  
  613. 14) Why does `bindkey ^a command-name' or 'stty intr ^-' do something funny?
  614.  
  615.   You probably have the extendedglob option set in which case ^ and #
  616.   are metacharacters.  ^a matches any file except one called a, so the
  617.   line is interpreted as bindkey followed by a list of files.  Quote the
  618.   ^ with a backslash or put quotation marks around ^a.
  619.  
  620.  
  621. 15) Why can't I bind \C-s and \C-q any more?
  622.  
  623.   The control-s and control-q keys now do flow control by default,
  624.   unless you have turned this off with `stty -ixon' or redefined the
  625.   keys which control it with `stty start' or `stty stop'.  (This is
  626.   done by the system, not zsh; the shell simply respects these
  627.   settings.)  In other words, \C-s stops all output to the terminal,
  628.   while \C-q resumes it.
  629.  
  630.   There is an option NO_FLOW_CONTROL to stop zsh from allowing flow
  631.   control and hence restoring the use of the keys: put `setopt
  632.   noflowcontrol' in .zshrc.
  633.  
  634.  
  635. 16) How do I execute command `foo' within function `foo'?
  636.  
  637.   The command `command foo' does just that.  You don't need this with
  638.   aliases, but you do with functions.  Note that error messages like
  639.         zsh: job table full or recursion limit exceeded
  640.   are a good sign that you tried calling `foo' in function `foo' without
  641.   using `command'.
  642.  
  643.  
  644. 17) Why do history substitutions with single bangs do something funny?
  645.  
  646.   If you have a command like "echo !-2:$ !$", the first history
  647.   substitution then sets a default to which later history substitutions
  648.   with single unqualified bangs refer, so that !$ becomes equivalent to
  649.   !-2:$.  The option CSH_JUNKIE_HISTORY makes all single bangs refer
  650.   to the last command.
  651.  
  652.  
  653. 18) Why does zsh kill off all my background jobs when I logout?
  654.  
  655.   Simple answer: you haven't asked it not to.  Zsh (unlike [t]csh) gives
  656.   you the option of having background jobs killed or not: the `nohup'
  657.   option exists if you don't want them killed.  Note that you can always
  658.   run programs with `nohup' in front of the pipeline whether or not the
  659.   option is set, which will prevent that job from being killed on
  660.   logout.  (Nohup is actually an external command.)
  661.  
  662.   The `disown' builtin is very useful in this respect: if zsh informs
  663.   you that you have background jobs when you try to logout, you can
  664.   `disown' all the ones you don't want killed when you exit.  This is
  665.   also a good way of making jobs you don't need the shell to know about
  666.   (such as commands which create new windows) invisible to the shell.
  667.  
  668.  
  669. 19) I don't have root access: how do I make zsh my login shell?
  670.  
  671.   Unfortunately, on many machines you can't use `chsh' to change your
  672.   shell unless the name of the shell is contained in /etc/shells, so if
  673.   you have your own copy of zsh you need some sleight-of-hand to use it
  674.   when you log on.  (Simply typing `zsh' is not really a solution since
  675.   you still have your original login shell waiting for when you exit.)
  676.   
  677.   The basic idea is to use `exec <zsh-path>' to replace the current
  678.   shell with zsh.  Often you can do this in a login file such as
  679.   .profile (if your shell is sh or ksh) or .login (if it's csh).  Make
  680.   sure you have some way of altering the file (e.g. via FTP) before you
  681.   try this as `exec' is often rather unforgiving.
  682.  
  683.   If you have zsh in a subdirectory `bin' of your home directory,
  684.   put this in .profile:
  685.     [ -f $HOME/bin/zsh ] && exec $HOME/bin/zsh -l
  686.   or if your login shell is csh or tcsh, put this in .login:
  687.     if ( -f ~/bin/zsh ) exec ~/bin/zsh -l
  688.   (in each case the -l tells zsh it is a login shell).  
  689.  
  690.   It's not a good idea to put this (even without the -l) into .cshrc, at
  691.   least without some tests on what the csh is supposed to be doing, as
  692.   that will cause _every_ instance of csh to turn into a zsh and will
  693.   cause csh scripts (yes, unfortunately some people write these) which
  694.   do not call `csh -f' to fail.  If you want to tell xterm to run zsh,
  695.   change the SHELL environment variable to the full path of zsh at the
  696.   same time as you exec zsh.  If you have to exec zsh from your .cshrc,
  697.   a minimum safety check is `if ($?prompt) exec zsh'.
  698.  
  699.   If you like your login shell to appear in the process list as '-zsh',
  700.   you can link zsh to -zsh (e.g. by `ln -s ~/bin/zsh ~/bin/-zsh') and
  701.   change the exec to `exec -zsh'.  (Make sure -zsh is in your path.)
  702.   This has the same effect as the `-l' option.
  703.  
  704.   Footnote: if you DO have root access, make sure zsh goes in
  705.   /etc/shells on all appropriate machines, including NIS clients, or you
  706.   may have problems with FTP to that machine.
  707.  
  708.  
  709. 20) Shouldn't zsh be more/less like ksh/(t)csh?
  710.  
  711.   People often ask why zsh has all these `unnecessary' csh-like features,
  712.   or alternatively why zsh doesn't understand more csh syntax.  This is
  713.   far from a definitive answer and the debate will no doubt continue.
  714.  
  715.   Paul's object in writing zsh was to produce a ksh-like shell which
  716.   would have features familiar to csh users.  For a long time, csh was
  717.   the preferred interactive shell and there is a strong resistance to
  718.   changing to something unfamiliar, hence the additional syntax and
  719.   CSH_JUNKIE options.  This argument still holds.  On the other hand,
  720.   the arguments for having what is close to a plug-in replacement for ksh
  721.   are, if anything, even more powerful:  the deficiencies of csh as a
  722.   programming language are well known (look in any Usenet FAQ archive, e.g.
  723.     rtfm.mit.edu:pub/usenet-by-group/news.answers/unix-faq/shell/csh-whynot
  724.   if you are in any doubt) and zsh is able to run many standard scripts
  725.   such as /etc/rc.
  726.   
  727.   Of course, this makes zsh rather large and quite messy so that it
  728.   seems to appeal mainly to hackers.  The only answer, perhaps not
  729.   entirely satisfactory, is that you have to ignore the bits you don't
  730.   want.
  731.  
  732.  
  733. 21) What bugs are currently known and unfixed?
  734.  
  735.   Here are some of the more well-known ones, very roughly in decreasing
  736.   order of significance.  Many of these can also be counted against
  737.   differences from ksh in question 5); note that this applies to the
  738.   latest beta version and that simple bugs are often fixed quite
  739.   quickly.  There is a file BUGS in the source distribution with more
  740.   detail.
  741.  
  742.   Certain built-ins won't allow the `VAR=value command ...' assignment.
  743.     N.B.: `exec foo=bar command' is a workaround for exec.  Also, from 2.6
  744.     builtins should correctly unset VAR after the command, except
  745.     for special variables (bug) and typeset/export commands (deliberate).
  746.   The `histlit' option adds newlines to lines in the history (and is
  747.     broken in several other ways, e.g. !:x word selection; it may be
  748.     removed).
  749.   `time' is ignored with builtins and can't be used with {...} or (...);
  750.     in shells with no job control the command name is blank.
  751.   `set -x' (`setopt xtrace') still has a few glitches.
  752.   The :q modifier doesn't split words and -q and -x don't work for variables.
  753.   In vi mode, `u' can go past the original modification point.
  754.   Autocd won't use globbed filenames.
  755.   The singlelinezle option has problems with prompts containing escapes.
  756.   Builtins at the end of a pipeline lose their status to previous commands.
  757.   The `r' command does not work inside $(...) or `...` expansions.
  758.  
  759.   Note that a few recent changes introduce incompatibilities (these
  760.   are not bugs):
  761.   An option CSH_JUNKIE_PAREN has proved necessary for the syntax `if (
  762.     <condition> ) <code>' and for similar `for' and `while' (but not
  763.     `foreach') commands.  This is because it is valid Bourne/Korn shell
  764.     syntax to have a subshell command immediately after if, and the
  765.     default syntax should be compliant with that.
  766.   You also need CSH_JUNKIE_PAREN if you want to use the syntax
  767.     `if [[ ... ]] command'; this was mainly here for csh compatibility.
  768.     Remember you can use `[[ ... ]] && command' to do the same thing.
  769.   Assignment of `...` and $(...) to variables in the form `foo=$(...)'
  770.     is now always scalar; previously the command output was split and
  771.     array assignment performed if more than one word resulted.  You
  772.     can still generate an array vie `foo=($(...))', which was always
  773.     the safe way of doing it.  Again, this is for Bourne/Korn compliance.
  774.   The -h option to compctl has been removed (use `-k hosts' for the
  775.     same effect); automatic handling of hosts after '@' has been removed
  776.     (use e.g. `compctl -u -x "n[-1,@]" -k hosts -- finger').
  777.   Handling of backslashes in `echo' and `print' has changed.
  778.   umask's behaviour with respect to symbolic operators has reversed
  779.     (and is now ksh-compatible).
  780.   The option CSH_JUNKIE_TILDE has been upgraded to GLOB_SUBST: instead
  781.     of just ~'s and ='s, all characters become eligible for file
  782.     expansion and globbing when the option is set.  (The option was
  783.     not present in 2.3 at all.)
  784.  
  785.   There is at least one common bug which is not due to zsh.  If you have
  786.   abnormal behaviour with file descriptor 4, it's because your password
  787.   database is being read from the Network Information System and
  788.   getpwent() left this fd open.
  789.  
  790.  
  791. 22) Where do I report bugs, get more info / who's working on zsh?
  792.  
  793.   The shell is being maintained by various (entirely self-appointed)
  794.   subscribers to the mailing list,
  795.     zsh-list@sterling.com so any suggestions, complaints,
  796.   questions and matters for discussion should be sent there.  If you
  797.   want someone to mail you directly, say so.  Most patches to zsh appear
  798.   there first.
  799.   
  800.   A lower-volume list,
  801.     zsh-announce@sterling.com
  802.   exists for announcements of new features and proposed changes
  803.   requiring some decisions.
  804.  
  805.   Both lists are handled by an automated server.  The instructions for
  806.   zsh-announce are the same as for zsh-list: just change zsh-list to
  807.   zsh-announce everywhere in the following.
  808.  
  809.   To join zsh-list, send email to
  810.     Majordomo@sterling.com
  811.   containing
  812.     subscribe zsh-list <optional-address>
  813.   where <optional-address> can be blank if you want to subscribe from
  814.   your current email address.  Send the message `help' to the same
  815.   address for help on the list server; `unsubscribe zsh-list' also
  816.   works. (Don't send this to the list!) The list manager, Rick Ohnemus,
  817.   can be reached at
  818.     owner-zsh-list@sterling.com
  819.   (or `rick' at the same adress).
  820.  
  821.   The list (everything since May 1992) is archived in
  822.     ftp.sterling.com:zsh/zsh-list/YY-MM
  823.   where YY-MM are the year and month in digits.
  824.  
  825.   Of course, you can also post zsh queries to the Usenet group
  826.   comp.unix.shell; if all else fails, you could even e-mail me.
  827.  
  828.  
  829. 23) What's on the wish-list?
  830.  
  831.   Ksh/sh compatibility could be improved if required.  This would
  832.     be a useful long term goal.
  833.   Option for glob qualifiers to follow perl syntax.
  834.   Option to quote !-history lexically via '' but not "".
  835.   Binding of shell functions (or commands?) to key strokes --
  836.     requires some way of accessing the editing buffer from functions
  837.     and probably of executing zle functions as a command.
  838.   trap '...' FOO should be eval'd rather than called as a function.
  839.   `PATH=' should clear the PATH:  it inserts `.'; use `unset PATH' or
  840.     `path=()' for the time being.  This is not really a bug as the .
  841.     would be used internally in any case (cf. ksh).
  842.   Users should be able to create their own foopath/FOOPATH array/path
  843.     combinations.
  844.  
  845.  
  846. Acknowledgments:
  847.  
  848. Thanks to zsh-list, in particular Bart Schaefer, for suggestions
  849. regarding this document; thanks to Jim Mattson, Bas de Bakker and now
  850. Richard Coleman for their hard work as archivists, and to Peter Gray
  851. for maintaining the mailing list, without which zsh might easily have
  852. died, and to the latest list maintainer, Rick Ohnemus.  The world is
  853. eternally in the debt of Paul Falstad for inventing zsh in the first
  854. place (though the wizzo extended completion is by Sven Wishnowsky).
  855.